home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!austern
- From: jbuck@Synopsys.COM (Joe Buck)
- Newsgroups: comp.std.c++
- Subject: Re: strings as stl container
- Date: 04 Apr 1996 10:15:18 PST
- Organization: Synopsys Inc., Mountain View, CA 94043-4033
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <4jvdnd$c9c@hermes.synopsys.com>
- References: <199604020907.LAA06972@bredex.bredex.de>
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: 4 Apr 1996 02:55:41 GMT
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMWQRt0y4NqrwXLNJAQFVCwIAli45uYsIJxE/R7zrjj+vOhMBEpH7hbp2
- bib37fRT6wJV7ocVQ0EEsjKlfEhnbD/9uizBlUIGUE/a9VVIezCToQ==
- =lh7T
- Originator: austern@isolde.mti.sgi.com
-
- Nico Josuttis <nico@bredex.de> writes:
- >Due to the fact that strings have iterator support,
- >the could be used as stl container.
-
- Correct.
-
- >But two things are missing:
- > - push_back()
- > - clear()
-
- No, these are not needed.
-
- >These are fundamental operations, that the corresponding "normal"
- >container, namely vector, has.
-
- The documentation I have does not list clear as a member of vector.
-
- >Especially push_back() would be essential to use insert iterators
- >for strings.
-
- No, this isn't true. You need push_back to use back_insert_iterator,
- but insert_iterator only needs insert, which string does have.
-
- Try the following program (works with gcc 2.7.2/libg++ 2.7.1 and appears
- to conform to the standard if I didn't screw up):
-
- ----------------------
- #include <string>
- #include <iterator>
- #include <algorithm>
-
- const char text[] = "This is text\n";
- const char text2[] = "even more ";
-
- int main()
- {
- string foo;
- insert_iterator<string> iter = inserter(foo, foo.begin());
- copy(text, text + sizeof(text)-1, iter);
- cout << "value of foo: " << foo;
-
- copy(text2, text2 + sizeof(text2)-1, inserter(foo, foo.begin()+8));
- cout << "value of foo: " << foo;
- }
- ----------------------
-
- This prints
- value of foo: This is text
- value of foo: This is even more text
-
- --
- -- Joe Buck <jbuck@synopsys.com> (not speaking for Synopsys, Inc)
-
- Work for something because it is good,
- not just because it stands a chance to succeed. -- Vaclav Havel
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-